from pydantic import BaseModel, Field
from typing import Optional, List
from app.schemas.base import BaseSchema

class DepartmentBase(BaseModel):
    """部门基础模式"""
    name: str = Field(..., description="部门名称")
    parent_id: Optional[int] = Field(None, description="父部门ID")
    sort: int = Field(0, description="排序")
    status: bool = Field(True, description="状态：True-启用，False-禁用")

class DepartmentCreate(DepartmentBase):
    """创建部门模式"""
    pass

class DepartmentUpdate(DepartmentBase):
    """更新部门模式"""
    name: Optional[str] = Field(None, description="部门名称")

class DepartmentInDB(DepartmentBase, BaseSchema):
    """数据库中的部门模式"""
    pass

class DepartmentOut(DepartmentInDB):
    """部门输出模式"""
    children: List["DepartmentOut"] = Field(default=[], description="子部门列表")
    user_count: int = Field(0, description="用户数量")

# 解决循环引用问题
DepartmentOut.update_forward_refs()